﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace STX.Lib.Utils
{
    public class Random
    {
        public static string NUMBER = "0,1,2,3,4,5,6,7,8,9";
        public static string CHAR = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        public static string NUMBER_AND_CHAR = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";

        public static int GetRandomNumber(int minValue, int maxValue)
        {
            System.Random random = new System.Random(System.Guid.NewGuid().GetHashCode());
            return random.Next(minValue, maxValue);
        }

        public static string GetRandomString(int stringLength)
        {
            return GetRandomString(NUMBER_AND_CHAR, stringLength);
        }

        public static string GetRandomString(string randomSourceList,int stringLength)
        {
            StringBuilder sb = new StringBuilder();
            string[] randomAry = randomSourceList.Split(',');
            for (int i = 0; i < stringLength; i++)
            {
                string str = randomAry[GetRandomNumber(0, randomAry.Length)];
                if (str.Length == 1 && (str == "0" || str.ToLower() == "o"))
                {
                    str = "1";
                }
                sb.Append(str);
            }
            return sb.ToString();
        }

        public static int GetFakeNumberByTime()
        {
            //todo
            return 0;
        }
    }
}
